package com.ljl.ssm.controller;


import com.ljl.ssm.entity.User;
import com.ljl.ssm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author BaoZhou
 * @since 2019-07-07
 */
@Controller
public class UserController {

    @Autowired
    IUserService userService;

    @RequestMapping(value = "/doLogin",method = RequestMethod.POST)
    public String login(Model model,
                        @RequestParam("username") String name,
                        @RequestParam("password") String password,
                        HttpSession session) {

        User user = userService.get(name, password);
        if (null == user) {
            model.addAttribute("msg", "请重新输入");
            return "login";
        }
        session.setAttribute("user", user);

        return "redirect:/";
    }
}

